package arts.spbu.testswing;

import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: pev67021
 * Date: 03.12.12
 * Time: 11:09
 */
public class DataModel extends AbstractTableModel {
    private ArrayList<ArrayList<String>> data;

    /*public DataModel(ArrayList<ArrayList<String>> data) {
        this.data = data;
    } */

    public DataModel() {
        super();
        //this.data = null;
    }

    public void setData(ArrayList<ArrayList<String>> source) {
        data = source;
        this.fireTableStructureChanged();
        this.fireTableDataChanged();
    }

    @Override
    public int getRowCount() {
        if (data != null)
            return data.size() - 1;
        return 0;
    }

    @Override
    public int getColumnCount() {
        if (data != null)
            return data.get(0).size();
        return 0;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        if (data != null)
            return data.get(rowIndex + 1).get(columnIndex);
        return null;
    }

    /*public void setValueAt(String value, int row, int col) {
        if (data == null)
            return;
        ArrayList<String> temp = data.get(row + 1);
        temp.set(col, value);
        data.set(row + 1, temp);
        fireTableCellUpdated(row, col);
    } */

    public String getColumnName(int column) {
        return data.get(0).get(column);
    }

}
